package JTabbedPane;
import javax.swing.*;
import java.awt.*;

public class MyFrame extends JFrame{
    JTabbedPane jtp;
    JPanel jp1,jp2,jp3;
    public MyFrame() {
        this.setSize(350, 200);
        this.setTitle("JTabbedPane Demo.");
        // 默认this.setLayout(new BorderLayout());

        jp1 = new JPanel();
        jp1.setBackground(Color.RED);
        jp2 = new JPanel();
        jp2.setBackground(Color.GREEN);
        jp3 = new JPanel();
        jp3.setBackground(Color.BLUE);
        jtp = new JTabbedPane();
        jtp.add("红色",jp1);
        jtp.add("绿色",jp2);
        jtp.add("蓝色",jp3);
        this.add(jtp,BorderLayout.CENTER);

        this.setLocationRelativeTo(null); // 将窗口居中
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 响应窗口关闭按钮
        this.setVisible(true);  // 将窗口显示出来
    }

    public static void main(String[] args)
    {
        new MyFrame();
    }
}